package com.atguigu.yygh.hosp.controller.user;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/hospital")
public class UserHospitalController {
    @Autowired
    private HospitalService hospitalService;

    @PostMapping("/{pageNum}/{pageSize}")
    //不建议接口复用,建议方法复用
    public R getHospitalPage(@PathVariable Integer pageNum, @PathVariable Integer pageSize, @RequestBody HospitalQueryVo hospitalQueryVo){
        Page<Hospital> page = hospitalService.page(pageNum, pageSize, hospitalQueryVo);
        return R.ok().data("items",page.getContent()).data("total",page.getTotalElements());
    }

    //对医院信息进行模糊查询
    @GetMapping("/{hosname}")
    public R getHospitalListByHosname(@PathVariable String hosname){
        List<Hospital> hospitals = hospitalService.getHospitalListByHosname(hosname);
        return R.ok().data("items",hospitals);
    }

    //根据医院编号查询医院信息
    @GetMapping("/info/{hoscode}")
    public R getHospitalByHoscode(@PathVariable String hoscode){
        Hospital hospital = hospitalService.getUserHospitalByHoscode(hoscode);
        return R.ok().data("item",hospital);
    }
}